package com.neutech.dao.impl;

import com.neutech.constant.Constant;
import com.neutech.dao.BusinessDAO;
import com.neutech.entity.Business;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BusinessDAOImpl implements BusinessDAO {
    private QueryRunner queryRunner =new QueryRunner(Constant.dateSource);
    @Override
    public List<Business> selectAll() {
        List<Business> businessList = new ArrayList<>();
        try {
            queryRunner.execute("select * from business",
                    new ResultSetHandler<Object>() {
                        @Override
                        public Object handle(ResultSet resultSet) throws SQLException {
                            while (resultSet.next()){
                                Business business =new Business();
                                business.setBusinessId(resultSet.getInt("business_id"));
                                business.setPassword(resultSet.getString("password"));
                                business.setBusinessName(resultSet.getString("business_name"));
                                business.setBusinessAddress(resultSet.getString("business_address"));
                                business.setBusinessName(resultSet.getString("business_explain"));
                                business.setStartPrice(resultSet.getBigDecimal("start_price"));
                                business.setDeliveryPrice(resultSet.getBigDecimal("delivery_price"));
                                businessList.add(business);
                            }

                            return null;
                        }
                    });
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return businessList;
    }

    @Override
    public void insert(Business business) {

    }

    @Override
    public void update(Business business) {

    }

    @Override
    public void delete(Business business) {

    }

    @Override
    public Business selectBybusinessName(String businessNameDate) {
        return null;
    }
}
